﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using XoLib.Manager;

namespace XoLib.Web
{
    /// <summary>
    /// WebPageAction
    /// </summary>
    /// <example>  </example>/// 
    [Flags]
    public enum WebPageAction
    {
        /// <summary>
        /// Web Get
        /// </summary>
        GET = 0,
        /// <summary>
        /// Web Post
        /// </summary>
        POST = 1,
    }

    /// <summary>
    /// Stock class Type and enable action
    /// </summary>
    /// <example>  </example>/// 
    public struct pages
    {
        /// <summary>
        /// class Type
        /// </summary>
        /// <example>  </example>///
        public Type type;

        /// <summary>
        /// Enable action
        /// </summary>
        /// <example>  </example>///
        public WebPageAction Action;
    }

    /// <summary>
    /// Affect extention to the class
    /// </summary>
    /// <example> [WebPageType(".aspx", WebPageAction.GET)]  </example>/// 
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class WebPageType : System.Attribute, IGenericType<pages>
    {
        /// <summary>
        /// constructor
        /// </summary>
        /// <example>  </example>/// 
        public WebPageType(string extention, WebPageAction allow)
        {
            this.Extention = extention;
            this.Allow = allow;
        }

        /// <summary>
        /// Extention
        /// </summary>
        /// <example>  </example>/// 
        public string Extention { get; private set; }
        /// <summary>
        /// Allow
        /// </summary>
        /// <example>  </example>/// 
        public WebPageAction Allow { get; private set; }

        /// <summary>
        /// Register
        /// </summary>
        /// <example>  </example>/// 
        public void InsertIn(Dictionary<string, pages> dic, Type ClassType)
        {
            dic.Add(Extention, new pages { Action = Allow, type = ClassType });
        }

    }

    /// <summary>
    /// Interface IWebPage
    /// </summary>
    /// <example>  </example>/// 
    public interface IWebPage
    {
        /// <summary>
        /// Method if you receive a GET
        /// <para>
        /// <param name="webRequest">WebRequest</param>
        /// </para>
        /// </summary>
        /// <returns>System.IO.Stream</returns>
        System.IO.Stream GET(WebRequest webRequest);

        /// <summary>
        /// Method if you receive a POST
        /// <para>
        /// <param name="webRequest">WebRequest</param>
        /// </para>
        /// </summary>
        /// <returns>System.IO.Stream</returns>
        System.IO.Stream POST(WebRequest webRequest);

        /// <summary>
        /// Performe Action After GET or POST
        /// </summary>
        void Action();
    }
}
